home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectInput / DIConfig / iclassfact.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  1.7 KB  |  108 lines

  1. //-----------------------------------------------------------------------------
  2. // File: iclassfact.cpp
  3. //
  4. // Desc: Implements the class factory for the UI.
  5. //
  6. // Copyright (C) 1999-2001 Microsoft Corporation. All Rights Reserved.
  7. //-----------------------------------------------------------------------------
  8.  
  9. #include "common.hpp"
  10.  
  11.  
  12. //QI
  13. STDMETHODIMP CFactory::QueryInterface(REFIID riid, LPVOID* ppv)
  14. {
  15.     //null the put parameter
  16.     *ppv = NULL;
  17.  
  18.     if ((riid == IID_IUnknown) || (riid == IID_IClassFactory))
  19.     {
  20.         *ppv = this;
  21.         AddRef();
  22.         return S_OK;
  23.     }
  24.  
  25.     return E_NOINTERFACE;
  26.  
  27. }
  28.  
  29.  
  30.  
  31. //AddRef
  32. STDMETHODIMP_(ULONG) CFactory::AddRef()
  33. {
  34.     return InterlockedIncrement(&m_cRef);
  35. }
  36.  
  37.  
  38. //Release
  39. STDMETHODIMP_(ULONG) CFactory::Release()
  40. {
  41.  
  42.     if (InterlockedDecrement(&m_cRef) == 0)
  43.     {
  44.         delete this;
  45.         return 0;
  46.     }
  47.  
  48.     return m_cRef;
  49. }
  50.  
  51.  
  52. //CreateInstance
  53. STDMETHODIMP CFactory::CreateInstance(IUnknown* pUnkOuter, REFIID riid, LPVOID *ppv)
  54. {
  55.     HRESULT hr = S_OK;
  56.  
  57.     //can't aggregate
  58.     if (pUnkOuter != NULL)
  59.     {
  60.         return CLASS_E_NOAGGREGATION;
  61.     }
  62.  
  63.     //create component
  64.     CDirectInputActionFramework* pDIActionFramework = new CDirectInputActionFramework();
  65.     if (pDIActionFramework == NULL)
  66.     {
  67.         return E_OUTOFMEMORY;
  68.     }
  69.  
  70.     //get the requested interface
  71.     hr = pDIActionFramework->QueryInterface(riid, ppv);
  72.  
  73.     //release IUnknown
  74.     pDIActionFramework->Release();
  75.     return hr;
  76.  
  77. }
  78.  
  79.  
  80. //LockServer
  81. STDMETHODIMP CFactory::LockServer(BOOL bLock)
  82. {
  83.     HRESULT hr = S_OK;
  84.     if (bLock)
  85.     {
  86.         InterlockedIncrement(&g_cServerLocks);
  87.     }
  88.     else
  89.     {
  90.         InterlockedDecrement(&g_cServerLocks);
  91.     }
  92.  
  93.     return hr;
  94. }
  95.  
  96.  
  97. //constructor
  98. CFactory::CFactory()
  99. {
  100.     m_cRef = 1;
  101. }
  102.  
  103.  
  104. //destructor
  105. CFactory::~CFactory()
  106. {
  107. }
  108.